import { put, takeEvery } from "redux-saga/effects"
import { UsersAction, USER_LIST, SET_USERLIST, USRE_SUCCESS, USRE_ERROR } from "../actions/user.action"
import userApi from '../../api/user'

// 获取用户列表
function* getUserList (action: UsersAction) {
    try {
        const { name = '', current } = action.payload
        yield put({ type: SET_USERLIST })
        const { data } = yield userApi.getUserList({ page: current, name })
        yield put({ type: USRE_SUCCESS, payload: data })
    } catch (error) {
        yield put({ type: USRE_ERROR })
    }

}

export default function* userSaga () {
    yield takeEvery(USER_LIST, getUserList)
}
